*Teele (2022) Analyses in main paper 

cd "YOUR DIRECTORY HERE"


************************************************************
*Look at 0.Read Me for details about the merging process
*Download CFS (2016) replication files. 
*run panel_all_women.do >creates panel_all_women.dta
*then run Turnout_District_Level.do > creates collapsed data. 
************************************************************



*****************
*Figure 1a: Eligibility pre and post reform 
*****************
use Turnout_District_Level_ladies, clear

collapse (sum) eligiblewomen eligiblemen castedvoteswomen castedvotesmen eligibleoverall (mean) turnout_DT turnoutwomen_DT turnoutmen_DT womensshareturnout_DT, by(year)

twoway line eligibleoverall eligiblemen eligiblewomen year, lwidth(vthick vthick vthick) lc(gs2 gs12 gs4) scheme(tufte)  xline(1919, lwidth(1) lc(gs12)) ytitle("Total Number of Eligible Voters", size(medlarge)) xtitle("Election Year", size(medlarge))  legend(label (2 "Men") label(3 "Women") label(1 "Total") col(1) ring(0) pos(5) order(1 3 2)) xsca(titlegap(*10)) xlab(1909 1912 1915 1918 1921 1924 1927) 
*Note, the above graph is the average of district level averages NOT the weighted average. the PR reform was in 1920, but I think prior to the election. 

graph export "./images/Fig1a.eps", replace



*stats cited in text:
sort year
gen dturnmen=turnoutmen-turnoutmen[_n-1]
gen dturnwomen=turnoutwomen-turnoutwomen[_n-1]
list year turnoutmen dturnmen turnoutwomen dturnwomen if inlist(year, 1918, 1921)

/*
      +---------------------------------------------------+
     | year   ~tmen_DT   dturnmen   t~wome~T   dturnwo~n |
     |---------------------------------------------------|
  4. | 1918   .6979596   .0089145   .4840755   -.0042904 |
  5. | 1921   .7569237   .0589641   .5751634    .0910878 |
     +---------------------------------------------------+

*/ 
 
***************************************************
*Figure 1b: National Level Turnout for Men and Women 
*(the Cox et al. sample doesn't include all municipalities)
***************************************************

 
*Turnout for men tm_w, women tw_w, and dffference td_w, from Tingsten (1937). The number of registered voters and total voters are from Nohlen's Elections in Europe
clear
input year	tm_w	tw_w	td_w	registered	total_votes	turn_total
1909	67.5	55.3	12.2	760277	490246	64.48255044
1912	68.8	57.7	11.1	809582	533182	65.85892473
1915	68.4	50.5	17.9	1086657	671293	61.77597899
1918	70.1	50.6	19.5	1186602	717446	60.46222744
1921	76.4	60.3	16.1	1351183	917736	67.92092559
1924	76.4	64		12.4	1412441	987185	69.89212293
1927	75.3	61.5	13.8	1484409	1010625	68.08265108
1930	81.4	74		7.4		1550077	1202101	77.55105069
1933	81.8	71.2	10.6	1643498	1255038	76.36382886



twoway line turn_total tm_w tw_w year, scheme(tufte) lwidth(vthick vthick vthick) lc(gs2 gs12 gs4) xline(1919, lwidth(1) lc(gs12)) ytitle("Average Turnout, Whole Country", size(medlarge)) xtitle("Election Year", size(medlarge))  legend(label (2 "Men") label(1 "Total") label(3 "Women") col(1) ring(0) pos(5) order(2 1 3) ) xsca(titlegap(*10)) xlab(1909 1912 1915 1918 1921 1924 1927 1930 1933) 

graph export "./images/Fig1b.eps", replace



******************************
*Figure 2: density Competition Replication 
******************************
use "CFS/Turnout_District_Level.dta", clear /*This is CFS's Data */ 
sort year PR_district
drop _merge
merge year PR_district using "CFS/AlternativeMargin.dta"
drop if _merge==2 /* PR-districts not in sample */


twoway (kdensity margin if year<1920, lwidth(vthick)) (kdensity min_distance1 if year>1920 & year<1930, lwidth(vthick)), ///
title("") xtitle("Margin of Victory" "most competitive                                              least competitive", size(medlarge)) ytitle("") legend(off)  text(2.5 .4 "Pre-reform, 1909-1918", size(med)) text(18 .18 "Post-reform, 1921-1927", size(med)) xsca(titlegap(*10)) ///
plotregion(lcolor(white) ilcolor(white)) graphregion(fcolor(white)) scheme(tufte) 

graph export "./images/Fig2.eps", replace

****************************
*Stats cited in text, how many districts became more competitive after reform?
****************************
*compare same district margin before and after.

drop if _merge==2 /* PR-districts not in sample */
sort SMD_district year
gen premargin1918=margin[_n-1]
replace premargin1918=. if year!=1921

count if min_distance<=premargin1918 & year==1921
  * 84 of pre-PR districts had smaller margin (more cometitive) after PR

count if min_distance>premargin1918 & year==1921
	* 8 of pre-PR districts had larger margin (less competitive) after PR
 
 
***********************************
*Figure 3 a: density turnout Replication 
**********************************

*Cox et al.'s Figure 2
use "CFS/Turnout_District_Level.dta", clear 

twoway (kdensity turnout if year<1920, lwidth(vthick)) (kdensity turnout if year>1920 & year<1930, lwidth(vthick)), title("") xtitle("") ytitle("") legend(order(1 "1909-1918" 2 "1921-1927"  ) pos(1) ring(0) col(1) off) scheme(tufte)  text(1.3 .22 "Pre-reform", size(medlarge)) text(3.2 .84 "Post-PR", size(medlarge)) yscale(range(0 5)) ylabel(0 [1] 5) xscale(range(0 1)) xlabel(0[.1]1) 

graph export "./images/Fig3a.eps", replace



************************************************************
*Figure 3 b & c : Density for men and women  
************************************************************

use "Turnout_District_Level_ladies.dta", clear 

*variance 
sum turnoutmen_DT if year==1918, detail
sum turnoutmen_DT if year==1921, detail 

*men variance in 1918: 0.012, in 1921 0.004
di (0.015-0.00445)/ 0.015
*= 70%

* women variance 0.034 0.013
sum turnoutwomen_DT if year==1918, detail
sum turnoutwomen_DT if year==1921, detail 

*figures cited in text 

di (0.037 - 0.0133)/ 0.037
*= 64%

*SD W 1921: 11.5 SD W 1918: 19.3 Men 1921 SD: 6.7 Men 1918 SD: 12.2


# delimit ; 
twoway 
(kdensity turnoutwomen_DT if year<1920, lwidth(vthick) lcolor(magenta)) 
(kdensity turnoutwomen_DT if year>1920 & year<1930, lwidth(vthick) lcolor(red)), 
title("")   ytitle("") xtitle("") legend(order(1 "1909-1918" 2 "1921-1927"  ) pos(10) ring(0) col(1) size(vsmall) off) xsca(titlegap(*10)) 
text(1.3 .09 "Pre-reform", color(magenta) size(medlarge))
text(2.75 .81 "Post-PR", color(red) size(medlarge))
name(g1, replace) scheme(tufte) 
yscale(range(0 5)) ylabel(0 [1] 5) xscale(range(0 1)) xlabel(0[.1]1)  ;  

# delimit cr
graph export "./images/Fig3c.eps", replace


*Men
# delimit ; 
twoway 
(kdensity turnoutmen_DT if year<1920, lwidth(vthick) lcolor(blue)) 
(kdensity turnoutmen_DT if year>1920 & year<1930, lwidth(vthick) lcolor(navy)), 
title("")  ytitle("") 
legend(order(1 "1909-1918" 2 "1921-1927"  ) pos(10) ring(0) col(1) size(vsmall) off) xtitle("")
text(1.5 .4 "Pre-reform", color(blue) size(medlarge)) 
text(4.5 .9 "Post-PR", color(navy) size(medlarge))
xsca(titlegap(*10)) name(g2, replace) 
yscale(range(0 5)) ylabel(0 [1] 5) xscale(range(0 1)) xlabel(0[.1]1) 
scheme(tufte); 
# delimit cr
graph export "./images/Fig3b.eps", replace




**************************************
*Figure 4: Quantile graphs (replication of figure 6)
**************************************

use "Turnout_District_Level_ladies.dta", clear 

drop SMD_margin_quantile
xtile SMD_margin_quantile=SMD_margin, nq(6)

foreach type in men women  {

bysort year SMD_margin_quantile: egen mean_turnout_`type'=mean(turnout`type'_DT)
label var mean_turnout_`type' "Mean Voter Turnout, `type'"
}

bysort year SMD_margin_quantile: egen mean_turnout_DT=mean(turnout_DT)

gen m="m"
gen w="w"

foreach quantile in 1 2 3 4 5 6 {


gen g=mean_turnout_women-mean_turnout_men if year==1918 & SMD_margin_quantile==`quantile'
replace g=mean_turnout_women-mean_turnout_men if year==1921 & SMD_margin_quantile==`quantile'

replace g=round(g,.01)*100

# delimit ; 
twoway 
(scatter mean_turnout_DT year if year<1920 & SMD_margin_quantile==`quantile', mstyle(none) mlabel(g) mcolor(gs6) msize(tiny) lstyle(p1) lpattern(dash) lcolor(gs6) connect(l)) 

(scatter mean_turnout_DT year if year>1920 & SMD_margin_quantile==`quantile', mstyle(none) mlabel(g) mlabpos(9) mcolor(gs6) msize(tiny) lstyle(p1) lpattern(dash) lcolor(gs6) connect(l))

(scatter mean_turnout_men year if year<1920 & SMD_margin_quantile==`quantile', mstyle(none) mlabel(m) mlabpos(12)  lwidth(thick)  mlabcolor(navy) msize(tiny) lstyle(p1) lpattern(solid) lcolor(navy) connect(l)) 

(scatter mean_turnout_men year if year>1920 & SMD_margin_quantile==`quantile',  mstyle(none) mlabel(m) mlabpos(12) lwidth(thick) mlabcolor(navy) msize(tiny) lstyle(p1) lpattern(solid) lcolor(navy) connect(l))

(scatter mean_turnout_women year if year<1920 & SMD_margin_quantile==`quantile',  mstyle(none) mlabel(w) mlabpos(6) mlabcolor(magenta) lwidth(thick)  msize(tiny) lstyle(p1) lpattern(solid) lcolor(magenta) connect(l)) 

(scatter mean_turnout_women year if year>1920 & SMD_margin_quantile==`quantile',  mstyle(none) mlabel(w)  lwidth(thick) mlabpos(6) mlabcolor(magenta) msize(tiny) lstyle(p1) lpattern(solid) lcolor(magenta) connect(l))

, 

title(Q`quantile') graphregion(fcolor(white)) scheme(s2mono) legend(off) ytitle("") xtitle("") xscale(range(1909 1927)) xlabel(1909[3]1927) name(DV_`quantile', replace) graphregion(color(white))
 nodraw; 

# delimit cr

drop g 

}

graph combine DV_1  DV_2 DV_3 DV_4  DV_5  DV_6 , xcommon ycommon graphregion(fcolor(white)) scheme(tufte) row(3) col(2) 


graph export "./images/Fig4.eps", replace



************************************
*Figure 5: Change in Gender Gap based on Change in competition ranking
*************************************
use "Turnout_District_Level_ladies.dta", clear 
sort year PR_district
cap drop _merge
merge year PR_district using "CFS/AlternativeMargin.dta"

drop if _merge==2 /* PR-districts not in sample */

gen did=ch_turnoutwomen-ch_turnoutmen
sort SMD_district year
gen premargin1918=SMD_margin_pre[_n-1]
replace premargin1918=. if year!=1921

*higher margin means less competitive. "Field" option of the rank command Rank assigns a 1 to the highest value. So using field means highest rank=most competitive
egen comprank1918=rank(premargin1918) if year==1921, field
egen comprank1921=rank(min_distance1) if year==1921, field 
scatter comprank1921 comprank1918

gen ch_comp=comprank1921-comprank1918 if year==1921

twoway(lfitci did ch_comp, estopts(cluster(PR_district)) lwidth(vthick) ) (scatter did ch_comp, msym(oh))  if year==1921, ytitle("Change in Women's Turnout - Change in Men's") xtitle("Change in Competition" "became less  competitive                                  became more competitive") yline(0, lcolor(red)) xline(0, lcolor(red))  legend(off) xsca(titlegap(*10)) scheme(tufte) name(g2, replace)

graph export "./images/Fig5.eps", replace








